--get the list of columns
IF OBJECT_ID(N'tempdb..#Columns') IS NOT NULL DROP TABLE #Columns
SELECT COLUMN_NAME AS ColumnName
INTO #Columns
FROM information_schema.columns 
WHERE TABLE_NAME = 'FinancialReport'
	AND COLUMN_NAME NOT IN ('Id', 'CompanyId', 'Year', 'Type')


IF OBJECT_ID(N'tempdb..#FreeSpace') IS NOT NULL DROP TABLE #FreeSpace
CREATE TABLE #FreeSpace (
	[ColumnName] varchar(100) NULL,
	[EmptyPercentage] float NULL
)

DECLARE @ColumnName varchar(100)
		, @Percentage float
		, @Command nvarchar(max)

DECLARE ColumnsCursor CURSOR FOR
SELECT ColumnName
FROM #Columns

OPEN ColumnsCursor
FETCH NEXT FROM ColumnsCursor INTO @ColumnName

WHILE @@FETCH_STATUS = 0
BEGIN
	SET @Command = 
	' DECLARE @Percentage float
	
	SELECT @Percentage = (100.0 * SUM(
			CASE 								
				WHEN [' + @ColumnName + '] = 0.0	THEN 1 															
				ELSE 0.0 
			END
			) / COUNT(1))
	FROM [dbo].[FinancialReport]
	INSERT INTO #FreeSpace ([ColumnName],[EmptyPercentage])	
	VALUES (''' + @ColumnName + ''', @Percentage)'
	
	EXEC (@COMMAND)
		
	FETCH NEXT FROM ColumnsCursor INTO @ColumnName
END

--print results
SELECT [ColumnName]
	, CAST ([EmptyPercentage] AS NUMERIC(10,2)) as PercentageOfZeroValues
FROM #FreeSpace
ORDER BY [EmptyPercentage] DESC

--drop temp data
CLOSE ColumnsCursor   
DEALLOCATE ColumnsCursor
IF OBJECT_ID(N'tempdb..#Columns') IS NOT NULL DROP TABLE #Columns
IF OBJECT_ID(N'tempdb..#FreeSpace') IS NOT NULL DROP TABLE #FreeSpace